package com.gxa.dao.impl;

import com.gxa.common.Constants;
import com.gxa.dao.ParamDao;
import com.gxa.dbutils.JdbcBuild;
import com.gxa.pojo.Basicinfo;

import java.sql.SQLException;
import java.util.List;

public class ParamDaoImpl extends JdbcBuild implements ParamDao {
    @Override
    public List<Basicinfo> queryparamlist(Integer p1, Integer p2) throws SQLException {
        String sql = "select * from basicinfo where del_status=? limit ?,?";
        Object[] o = {Constants.Del_STATUS_OK,p1,p2};
        return super.queryListEntity(Basicinfo.class,sql,o);
    }

    @Override
    public List<Basicinfo> queryparamlist(Integer p1, Integer p2, String describes) throws SQLException {
        String sql = "select * from basicinfo where describes like '%"+describes+"%' and del_status=? limit ?,?";
        System.out.println(sql);
        Object[] o = {Constants.Del_STATUS_OK,p1,p2};
        return super.queryListEntity(Basicinfo.class,sql,o);
    }

    @Override
    public Integer countParam() throws SQLException {
        String sql = "select count(*) from basicinfo where del_status=?";
        return super.findAllForInt(sql, Constants.Del_STATUS_OK);
    }

    @Override
    public Integer countParam(String describes) throws SQLException {
        String sql = "select count(*) from basicinfo where describes like '%"+describes+"%' and del_status=?";
        return super.findAllForInt(sql, Constants.Del_STATUS_OK);
    }

    @Override
    public Integer addInfo(Basicinfo basicinfo) throws SQLException {
        String sql = "insert into basicinfo(describes,keywords,parameter,del_status) values(?,?,?,?)";
        Object[] params = {basicinfo.getDescribes(),basicinfo.getKeywords(),basicinfo.getParameter(),Constants.Del_STATUS_OK};
        return super.executeUpdate(sql,params);
    }

    @Override
    public Integer delInfo(String id) throws SQLException {
        String sql = "update basicinfo set del_status=? where id=?";
        Object[] params = {Constants.Del_STATUS_DEL,id};
        return super.executeUpdate(sql,params);
    }

    @Override
    public Integer updateInfo(Basicinfo basicinfo) throws SQLException {
        String sql = "update basicinfo set describes=?,keywords=?,parameter=? where id=?";
        Object[] params = {basicinfo.getDescribes(),basicinfo.getKeywords(),basicinfo.getParameter(),basicinfo.getId()};
        return super.executeUpdate(sql,params);
    }
}
